package com.myosw.action;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import javax.servlet.ServletException;

import org.apache.commons.beanutils.BeanUtils;

import com.myosw.pojo.Urls;
import com.myosw.service.ServiceService;

public class ServiceAction extends BaseAction {

	@Override
	public void execute() throws ServletException, IOException {
		root.put("menu", "service");
		printFreemarker("default/service.ftl", root);
	}
	
	public void addurl() throws IllegalAccessException, InvocationTargetException, ServletException, IOException 
	{
		root.put("menu", "service");
		if (!request.isSubmit()) 
		{
			printFreemarker("default/addurl.ftl", root);
			return;
		}
		
		Map<String, String[]> map = request.getParameterMap();
		Urls urls = new Urls();
		BeanUtils.populate(urls , map);
		if(serviceService.save(urls))
		{
			//printFreemarker("default/service.ftl", root);
			sendRedirect(request.basePath()+"user/service");
			return;
		}else {
			root.put("msg", "添加失败！");
			printFreemarker("default/addurl.ftl", root);
			return;
		}

		
	}
	
	ServiceService serviceService = new ServiceService();

}
